package wooqoo.widgetevent;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Toast;

public class FormActivity extends Activity {

	private String result = "남자";
	private RadioButton mem;
	private RadioButton women;
	private CheckBox fFood1;
	private CheckBox fFood2;
	private CheckBox fFood3;
	private String fFoodStr1 = "";
	private String fFoodStr2 = "";
	private String fFoodStr3 = "";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_form);
		
		mem = (RadioButton) findViewById(R.id.mem);
		women = (RadioButton) findViewById(R.id.women);
		fFood1 = (CheckBox) findViewById(R.id.fCheck1);
		fFood2 = (CheckBox) findViewById(R.id.fCheck2);
		fFood3 = (CheckBox) findViewById(R.id.fCheck3);
	}

	// 보통 크기버튼 이벤트
	public void btnClick(View v) {
		String msg = "";
		
		switch(v.getId()) {
			case R.id.nomalBtn: 
				msg = "보통 크기버튼 클릭됨";
				break;
			case R.id.smallBtn: 
				msg = "작은 크기버튼 클릭됨";
				break;
		}
		
		Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
	}
	
	public void checkGender(View v) {
		switch(v.getId()) {
			case R.id.mem :
				result = "남자";
				break;
			case R.id.women :
				result = "여자";
				break;
			case R.id.genderBtn :
				Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
				break;
		}
	}
	
	public void checkFood(View v) {
		String foodResult = "";
		
		switch(v.getId()) {
			case R.id.fCheck1 :
				fFoodStr1 = fFood1.isChecked() ? "자장면" : "";
				break;
			case R.id.fCheck2 :
				fFoodStr2 = fFood1.isChecked() ? "/" : "";
				fFoodStr2 += fFood2.isChecked() ? "우동" : "";
				break;
			case R.id.fCheck3 :
				if(fFood1.isChecked() || fFood2.isChecked()) fFoodStr3 = "/";
				else fFoodStr3 = "";
				
				fFoodStr3 += fFood3.isChecked() ? "탕수육" : "";
				break;
			case R.id.orderBtn :
				foodResult = fFoodStr1 + fFoodStr2 + fFoodStr3;
				
				Toast.makeText(getApplicationContext(), foodResult, Toast.LENGTH_SHORT).show();
				break;
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.form, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
}
